package org.slf4j.impl;

import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;

import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

public class LoggerFactory implements ILoggerFactory {
  
  ConcurrentMap<String, Logger> loggerMap;
  
  public LoggerFactory() {
    loggerMap = new ConcurrentHashMap<String, Logger>();
  }
  
  @Override
  public Logger getLogger(String name) {
    Logger slf4jLogger = loggerMap.get(name);
    if (slf4jLogger != null) {
      return slf4jLogger;
    } else {
      com.db.logging.Logger myLogger = new com.db.logging.Logger(name);
      
      Logger newInstance = new LoggerAdapter(myLogger);
      Logger oldInstance = loggerMap.putIfAbsent(name, newInstance);
      return oldInstance == null ? newInstance : oldInstance;
    }
  }
}
